Modeling and Reasoning about Computation : Theory and Applications of Automata , Languages , Undecidability , BDD , SAT , and SMT Methods through Declarative Programming
نویسندگان
چکیده
ly, the print command looks like this: print(<< a separator >>.join(map(str, list_of_things)) + "\t\t" + << a tail string >>) For example, print(" :-) ".join(map(str, [{’a’}, 10, {’a’:10}, {1:20}, []])) + " " + " (-: ") produces {’a’} :-) 10 :-) {’a’: 10} :-) {1: 20} :-) [] (-: The cool thing is that the format modifier function applied to strings formats the string in a given way (much like Unix’s sprintf). URL http://www. shocksolution.com/2011/11/python-string-format-examples/ gives a very nice set of examples to explain this. Let me present this through some examples. 16CHAPTER 2. A BRIEF TOUR OF PYTHON, DECLARATIVE PROGRAMMING • Suppose for some crazy reason, you want to print natural numbers 10 through 50 in decimal as follows: 10, 20, 30, 40, 50 This is achieved through: "{0:1d}, {1:2d}, {2:4d}, {3:8d}, {4:16d}".format(10,20,30,40,50)} • You can now print these numbers in binary, as as follows: 1010, 10100, 11110, 101000, 110010 through "{0:1b}, {1:2b}, {2:4b}, {3:8b}, {4:16b}".format(10,20,30,40,50) • Now obtain a, 14, 1e, 28, 32 through "{0:1x}, {1:2x}, {2:4x}, {3:8x}, {4:16x}".format(10,20,30,40,50) • Suppose x be variable in a program you have, and say x = 0.1234567890. • Suppose you are faced with printing this: ’sin(0.1234567890) = 1.2314e-01’. but you want things to be rounded up to 4 places, meaning 0.1234567890 must appear as 0.1235. • You can generate this entire string by doing this: "sin({0:.4f}) = {1:.4e}".format(0.1234567890, sin(0.123456789)) 2.1.9 Making a formatter function through a Lambda Here is an interesting example putting these ideas together: fm = lambda x: ’{0:3d}’.format(x) # each item is the "zeroth" item, hence "0:" list(map(fm, [1,2,30,400]))
منابع مشابه
Constraint Answer Set Programming
Constraint answer set programming (CASP) is a novel, promising direction of research whose roots go back to propositional satisfiability (SAT). SAT solvers are efficient tools for solving boolean constraint satisfaction problems that arise in different areas of computer science, including software and hardware verification. Some constraints are more naturally expressed by non-boolean constructs...
متن کاملProceedings of the 9 th International Workshop on Satisfiability Modulo Theories ( SMT ) 2011
s of Invited Talks Software Construction using Executable Constraints. Viktor Kuncak (EPFL) Constructing software that satisfies the desired properties can greatly benefit from solvers based on satisfiability modulo theories (SMT) paradigm. We propose a research program in which software construction and SMT technology become even more interconnected than today. Instead of checking properties o...
متن کاملKnowledge Representation, Computation, and Learning in Higher-order Logic
This paper contains a systematic study of the foundations of knowledge representation, computation, and learning in higher-order logic. First, a polymorphically-typed higher-order logic, whose origins can be traced back to Church’s simple theory of types, is presented. A model theory and proof theory for this logic are developed and basic theorems relating these two are given. A metric space of...
متن کاملSMT-Based Verification of Hybrid Systems
ion techniques Linear Phase-Portrait Partitioning [HWT95] Abstract complex dynamics splitting each location in multiple locations. Each location has a simple dynamic of the form a ≤ ẋ ≤ b, a, b ∈ R which approximate the complex dynamic in a specific interval. Predicate Abstraction [ADI06, Tiw08] A set of predicates defines a finite-state abstraction of the hybrid systems. The finite-state syste...
متن کاملThe Design of the Sixth Answer Set Programming Competition - - Report -
Answer Set Programming (ASP) is a well-known paradigm of declarative programming with roots in logic programming and non-monotonic reasoning. Similar to other closely-related problem-solving technologies, such as SAT/SMT, QBF, Planning and Scheduling, advances in ASP solving are assessed in competition events. In this paper, we report about the design of the Sixth ASP Competition, which is join...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2013